/**
 * 单 window 配置
 */
package cn.antia.cwin.window;

import java.util.*;

import cn.antia.cwin.Cele;
import cn.antia.cwin.SysConf;
import cn.antia.cwin.Output;

/**
 * @author sunkeei
 * @date Dec 1, 2007
 * @time 11:03:34 AM
 * @version 0.1
 */

public class SingleWindow implements Cloneable{
	private String id;			//window id
	private String table;		//window operate table,nullable
	private String action = SysConf.ACCEPT_URL;		//operate action
	private String method = SysConf.FORM_METHOD;		//方法(默认为 "post")
    private String desc;		//window　描述
	private String formName;	//表单名
	private int pageSize;		//每一页显示的记录
	private String type;		//类型/single/compact/popular
    private List<String> methods;	//method(String) (add,undate,delete)
    
    private Layout layout;          //布局属性
    private List<Cele> fields;		//fields
	private List<Output> extraColumns;		//扩展属性扩展属性<Output>对象
    
    public SingleWindow() {
        layout = new Layout();
        fields = new ArrayList<Cele>();
        extraColumns = new ArrayList<Output>();
    }
    
    public String getAction() {
		return action;
	}
	public void setAction(String action) {
		this.action = action;
	}
    public Layout getLayout() {
        return layout;
    }
    public void setLayout(Layout layout) {
        this.layout = layout;
    }

    public List<Cele> getFields() {
        return fields;
    }

    public void setFields(List<Cele> fields) {
        this.fields = fields;
    }

    public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getTable() {
		return table;
	}
	public void setTable(String table) {
		this.table = table;
	}
	public String getMethod() {
		return method;
	}
	public void setMethod(String method) {
		this.method = method;
	}
	public String getFormName() {
		return formName;
	}
	public void setFormName(String formName) {
		this.formName = formName;
	}
	public String getDesc() {
		return desc;
	}
	public void setDesc(String desc) {
		this.desc = desc;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
    public List<String> getMethods() {
        return methods;
    }
    public void setMethods(List<String> methods) {
        this.methods = methods;
    }

    public List<Output> getExtraColumns() {
        return extraColumns;
    }

    public void setExtraColumns(List<Output> extraColumns) {
        this.extraColumns = extraColumns;
    }

    public List<String> getFieldNames() {
        List<String> list = new ArrayList<String>();
        if (fields != null && fields.size() > 0) {
            for (Cele c : fields) {
                list.add(c.getField().getFieldName());
            }
        }
        return list;
    }

    public boolean hasField(String fieldName) {
        if(fields == null || fields.size() == 0){
			return false;
		}
        for (Cele field : fields) {
            if (field.getField().getFieldName().equals(fieldName)) {
                return true;
            }
        }
        return false;
    }

    public Object clone() throws CloneNotSupportedException {
		SingleWindow window = (SingleWindow)super.clone();
		List<Cele> temp = window.getFields();
		if(temp != null && temp.size() > 0){
			List<Cele> list = new ArrayList<Cele>();
            for (Cele ec : temp) {
                list.add(ec.clone());
            }
            window.setFields(list);
		}
		return window;
	}
}
